<?php
require_once './admin/header-iframe.php';
require_once './coon/connection.php';
?>

<?php
// 判断下请求参数是否带了文件路径，如果带了文件路径，就是从“我的贺卡”过来的
if ($_GET['userFile']) {
	?>
	<!-- 左侧菜单栏 -->
	<div class="container-fluid h-100">
		<div class="row h-100 ">
			<!-- 模板区域 -->
			<div class="col-1 h-100" style="border: #1d2124 1px solid; overflow :auto;">
				<ul class="list-group mr-auto ml-4 ">
					<!-- 模板列表 -->
					<li class="nav-item dropdown">
						<a href="<?= $_GET['userFile'] ?>" target="diyFrame"><?= $_GET['cardName'] ?>（重置贺卡）</a>
					</li>

				</ul>

			</div>
			<!-- Diy区域 -->
			<div class="col-10 h-100" style="overflow:hidden;">
				<iframe src="<?= $_GET['userFile'] ?>" class="w-100 h-100" name="diyFrame" id="diyFrame" style="border: 0;"></iframe>
			</div>
			<!-- 元素区域 -->
			<div class="col-1 h-100" style="border: #1d2124 1px solid; overflow :auto;">
				<div class="row" style="border: #1d2124 1px solid; margin-top: 5px" onclick="addSpanForIframe()">
					<span>输入框</span>
				</div>
				<hr>
				<?php
				$selectElSql = "select id, create_time, update_time, is_delete, e_name, saveAddress, file_name
					from greeting_card_element where is_delete = 0;";
				// 连接数据库，并查询
				$resultConfig = mysqli_query($GLOBALS['conn'], $selectElSql);

				// 循环输出所有查询结果
				while ($row = mysqli_fetch_array($resultConfig)) {
					$cardName = $row['e_name'];
					$saveAddress = substr($row['saveAddress'], 2);
					$fileName = $row['file_name'];
					?>
					<div class="row justify-content-center" style=" margin-top: 5px" onclick="addDivForIframe('<?= $saveAddress.'/'.$fileName?>')">
						<img src="<?= $saveAddress.'/'.$fileName?>" alt="" style="width: 50%">
					</div>
					<hr>
					<?php
				}
				?>

			</div>
		</div>
	</div>
	<?php

} else {
	?>
	<!-- 左侧菜单栏 -->
	<div class="container-fluid h-100">
		<div class="row h-100 ">
			<!-- 模板区域 -->
			<div class="col-1 h-100" style="border: #1d2124 1px solid; overflow :auto;">
				<ul class="list-group mr-auto ml-4 ">
					<h4 style="color: #00b0d9">选择模板</h4>
					<?php
					$selectSql = "select id, create_time, update_time,name,saveAddress,file_name
					from greeting_card_template where is_delete = 0;";
					// 连接数据库，并查询
					$resultConfig = mysqli_query($GLOBALS['conn'], $selectSql);

					// 循环输出所有查询结果
					while ($row = mysqli_fetch_array($resultConfig)) {
						$cardName = $row['name'];
						$saveAddress = substr($row['saveAddress'], 1);
						$fileName = $row['file_name'];
						?>
						<!-- 模板列表 -->
						<li class="nav-item dropdown">
							<a href="<?= $saveAddress . '/' . $fileName ?>" target="diyFrame"><?= $cardName ?></a>
						</li>

						<?php
					}
					?>

				</ul>
			</div>
			<!-- Diy区域 -->
			<div class="col-10 h-100" style="overflow:hidden;">
				<iframe src="" class="w-100 h-100" name="diyFrame" id="diyFrame" style="border: 0;"></iframe>
			</div>
			<!-- 元素区域 -->
			<div class="col-1 h-100" style="border: #1d2124 1px solid; overflow :auto;">
				<div class="row" style="border: #1d2124 1px solid; margin-top: 5px" onclick="addSpanForIframe()">
					<span>输入框</span>
				</div>
				<hr>
				<?php
				$selectElSql = "select id, create_time, update_time, is_delete, e_name, saveAddress, file_name
					from greeting_card_element where is_delete = 0;";
				// 连接数据库，并查询
				$resultConfig = mysqli_query($GLOBALS['conn'], $selectElSql);

				// 循环输出所有查询结果
				while ($row = mysqli_fetch_array($resultConfig)) {
					$cardName = $row['e_name'];
					$saveAddress = substr($row['saveAddress'], 2);
					$fileName = $row['file_name'];
					?>
					<div class="row justify-content-center" style="margin-top: 5px" onclick="addDivForIframe('<?= $saveAddress.'/'.$fileName?>')">
						<img src="<?= $saveAddress.'/'.$fileName?>" alt="" style="width: 50%">
					</div>
					<hr>
					<?php
				}
				?>

			</div>
		</div>
	</div>
	<?php
}
?>
	<script src="/static/js/main.js"></script>
	<!-- JavaScript代码 -->
	<!--<script>-->
	<!--</script>-->


<?php
require_once './admin/footer-iframe.php';
?>